package usecasecontrol;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import business.exceptions.BackendException;
import business.exceptions.BusinessException;
import business.externalinterfaces.CartItem;
import business.externalinterfaces.ProductSubsystem;
import business.externalinterfaces.ShoppingCart;
import business.externalinterfaces.ShoppingCartSubsystem;
import business.productsubsystem.ProductSubsystemFacade;
import business.shoppingcartsubsystem.ShoppingCartSubsystemFacade;
import business.util.StringParse;



public class BrowseAndSelectController  {
	////MORE NEW
	ProductSubsystem pss = new ProductSubsystemFacade();
	public List<String> getCatalogNames() throws BackendException {	
		
		return pss.getCatalogNames();	
	}
	
	public ShoppingCart getLiveShoppingCart() {
		return ShoppingCartSubsystemFacade.getInstance().getLiveCart();
	}
	
	public ShoppingCartSubsystem getShoppingCartSystem() {
		return ShoppingCartSubsystemFacade.getInstance();
	}
	
	public List<CartItem> getLiveCartItems() {
		ShoppingCart cart = getLiveShoppingCart();
		if(cart != null) return cart.getCartItems();
		return new ArrayList<CartItem>();
	}
	
	 public String readCartItemProdName(int pos){
		   // IProductSubsystem prodSS = new ProductSubsystemFacade();
			ShoppingCartSubsystem shopCartSS = ShoppingCartSubsystemFacade.getInstance();
			ShoppingCart cart = shopCartSS.getLiveCart();
			
			CartItem item = cart.getCartItems().get(pos);
			String name = item.getProductName();
			return name;
	  }
	  public String readCartItemUnitPrice(String prodName) throws BackendException{
		    ProductSubsystem prodSS = new ProductSubsystemFacade();
		    String price = prodSS.getProduct(prodName).getUnitPrice();
		return price;
	}
	  //run rules on quantity and return the total price 
	  public void runRulesOnQuantity(String prodName, String quantityReq) throws BackendException, BusinessException{
		  //implement	 
	  }
	  public String getCartItemTotalPrice(String price,String quantityReq){
		  String totalprice = StringParse.multiplyDoubles(price,
					quantityReq);
		  return totalprice;
	  }
	  
	  public void addCartItem(String name, String quantityReq, String totalprice, Integer positionOfEdit) 
	  		throws BackendException{
		  //implement
	  }
	 
	  public String getLiveCartTotalCost(){
		  
		  return "0.0";
	  }
	  public  boolean removeItemFromCart(String item, int pos){
		  
		  return true;
	  }
	 
	private static final Logger LOG = Logger
			.getLogger("BrowseAndSelectController.class.getName()");

	
	public BrowseAndSelectController() {
	}

}
